﻿from django.test import TestCase
from django.http import HttpResponse
from django.http import JsonResponse
from index.models import Mapuser,Group,Category,Point
import datetime
import time
import uuid
import json
import base64
import random
# Create your tests here.

def test1(request):
    dd = str(datetime.datetime.now())
    print(dd)
    ts = int(time.mktime(time.strptime(dd, '%Y-%m-%d %H:%M:%S.%f')))
    print(ts)


    a=str(uuid.uuid4())
    print(type(a),a)
    print(type(a.encode()),a.encode())
    s=base64.b64encode(a.encode())
    print(type(s),s)
    print(str(s)[2:50])
    m=base64.b64decode('ZDk2NGZlMWItZWNkYi00YTdkLTg3YjgtNzQ4MjU3NThlYmI4')
    print(m)
    print(m.decode(),type(m.decode()))

    return HttpResponse('1')

def test2(request):
    a = [[['Black iron ore','黑铁矿'],
['Marcasite','白铁矿'],
['crystal','水晶'],
['Diamonds','钻石'],
['gold mine','金矿'],
['Silver ore','银矿'],
['copper mine','铜矿'],
['coal mine','煤矿'],
['lapis lazuli','青金石'],
['rough','原石'],
['jade','玉石'],
['emerald','绿宝石']
],
[['book','书籍'],
['commemorative coin','纪念币'],
['Graffiti','涂鸦'],
['badge','徽章'],
['Garage Kit','手办'],
['Card','卡牌'],
['Paintings','画作'],
['Sculpture','雕塑'],
['stamp','邮票'],
['model airplane','航模'],
['specimen','标本'],
['letter','字母']
],
[['Shrem','史莱姆'],
['Tree monster','树怪'],
['human skeleton','骷髅'],
['Beetle','石甲虫'],
['Sprite','花妖'],
['Big bat','大蝙蝠'],
['Broken beast','崩坏兽'],
['Hydralisk','刺蛇'],
['Sea caterpillar','海毛虫'],
['Seberg','赛博格'],
['Last filmmaker','末影人'],
['Tcho-Tcho','丘丘人']
],
[['Maple','枫木'],
['Spruce','云杉'],
['Bamboo','竹子'],
['a birch','白桦'],
['Cypress','柏木'],
['pine','松木'],
['walnut','胡桃'],
['Camphor','樟木'],
['nanmu','楠木'],
['Elm','榆木'],
['Eucalyptus','垂香木'],
['Cuihua wood','萃华木']
],
[['raspberry','树莓'],
['forage grass','牧草'],
['Sweet flower','甜甜花'],
['Mint','薄荷'],
['wild strawberry','野草莓'],
['moss','苔藓'],
['fern','蕨菜'],
['Lily','百合'],
['purslane','马齿苋'],
['Bupleurum chinense','柴胡'],
['Jueyun pepper','绝云椒椒'],
['Daisy','雏菊']
],
[['wild boar','野猪'],
['squirrel','松鼠'],
['dove','鸽子'],
['lizard','蜥蜴'],
['Tibetan Fox','藏狐'],
['Water monkey','水猴子'],
['lycorma delicatula','斑衣蜡蝉'],
['woodworm moth','芳香木蠹蛾'],
['Polar bear','北极熊'],
['panda','熊猫'],
['little cat','小猫咪'],
['Corgi','柯基']
],
[['businessman','商人'],
['resident','居民'],
['tourist','游客'],
['explorer','探险家'],
['knight','骑士'],
['Active NPC','活动NPC'],
['hunter','猎人'],
['child','小孩'],
['rock Army','千岩军'],
['Sunspot','小黑子'],
['Jiaxin candy','嘉心糖'],
['scholar','学者']
],
[['Hat','帽子'],
['Mask','面具'],
['glass','杯子'],
['Mask','面具'],
['amulet','护身符'],
['Tears of Goddess','女神之泪'],
['Pocket Watch','怀表'],
['Pearl','珍珠'],
['Water repellent','避水珠'],
['squama','龙鳞'],
['Fortune cookie','幸运饼干'],
['Destiny coin','命运硬币']
],
[['Crucian carp','鲫鱼'],
['carp','鲤鱼'],
['Grass Carp','草鱼'],
['Loach','泥鳅'],
['Hairy crab','毛蟹'],
['Sardine','沙丁鱼'],
['Puffer fish','河豚'],
['river crab','河蟹'],
['Turtle','甲鱼'],
['yellow croaker','大黄鱼'],
['salmon','鲑鱼'],
['Neptune sea slug','大西洋海神海蛞蝓']
],
[['Blood flower','血色茶花'],
['Glazed Lily','琉璃百合'],
['Clear heart','清心'],
['Starstone','星石'],
['Ancient will','远古意志'],
['metal hydrogen','超导金属氢'],
['Wind god pupil','风神瞳'],
['Broken crystal','崩坏结晶'],
['Jinliulu','金柳露'],
['Colorless','无色小晶块'],
['Colorful fruit','彩果'],
['Warcraft Secrets','魔兽要诀']
]
]
    ni = 100000
    icon = 422
    icurl = 'https://kb.violet-umberto.com/iconurl/0_'
    for i in a :
        theg = Group.objects.get(id = ni)
        thenn = 0
        for j in i:
            cc = random.randint(0,1)
            ss = random.randint(1,6)
            print(theg.id,theg.title,j[0],j[1],icurl+str(icon)+'.png','pin-'+str(ss)+'.png',bool(cc),False)
            Category.objects.create(id=ni*100+thenn,name=j[0],title=j[1],iconurl=icurl+str(icon)+'.png',shadowurl='pin-'+str(ss)+'.png',cluster=bool(cc),status=False,grid=ni)
            icon +=1
            thenn += 1
        ni += 1
    return HttpResponse('1')

def test3(request):
    nowc = [['wild boar','野猪'],
['squirrel','松鼠'],
['dove','鸽子'],
['lizard','蜥蜴'],
['Tibetan Fox','藏狐'],
['Water monkey','水猴子'],
['lycorma delicatula','斑衣蜡蝉'],
['woodworm moth','芳香木蠹蛾'],
['Polar bear','北极熊'],
['panda','熊猫'],
['little cat','小猫咪'],
['Corgi','柯基']
]
    gridd = 100005
    cidd = 0
    for i in nowc:
        for j in range(100):
            x = random.randint(3000,6000)
            y = random.randint(3333,6666)

            conten = ''
            chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789@$#_%?'
            for t in range(600):
                conten= conten+chars[random.randint(0,67)]

            print((gridd*100+cidd)*1000+j,x,y,i[1]+str(j),conten,'https://kb.violet-umberto.com/3705af23-5acb-4cc2-a7dd-64abae424b76',gridd*100+cidd)

            Point.objects.create(id=(gridd*100+cidd)*1000+j,x=x,y=y,title=i[1]+str(j),content=conten,img='https://kb.violet-umberto.com/3705af23-5acb-4cc2-a7dd-64abae424b76',cid=gridd*100+cidd)
        cidd +=1
    return HttpResponse('1')


def test4(request):
    mapid = int(request.GET.get('mapId'))
    nowc = Category.objects.filter(id__startswith=mapid)
    listzong = []
    for i in nowc:
        listzong.append({"cid":i.id,"features":[]})
        nowp = Point.objects.filter(id__startswith=i.id).values('id','x','y')
        listzong[-1]["features"]=list(nowp)
        
    jsonzong ={"code":0,"data":{"list":listzong}}
    return JsonResponse(jsonzong)

def test5(request):
    mapid = 1000
    nowc = Category.objects.filter(id__startswith=1000)
    listzong = []
    for i in nowc:
        listzong.append({"cid":i.id,"features":[]})
        nowp = Point.objects.filter(id__startswith=i.id).values('id','x','y','title','img','content')
        listzong[-1]["features"]=list(nowp)
        
    jsonzong ={"code":0,"data":{"list":listzong}}
    return JsonResponse(jsonzong)


